package com.fire.market.repository.impl;


import com.fire.component.extension.Assert;
import com.fire.component.extension.BizCommonError;
import com.fire.component.extension.ExceptionFactory;
import com.fire.market.entity.UserPasswordDo;
import com.fire.market.mapper.UserPasswordDoMapper;
import com.fire.market.repository.UserPasswordRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class UserPasswordRepositoryImpl implements UserPasswordRepository {
    @Resource
    private UserPasswordDoMapper userPasswordDoMapper;
    @Override
    public UserPasswordDo selectUserPasswordByUserId(Integer userId) {
        Assert.notNull(userId, "userId is null");
        return userPasswordDoMapper.selectAllByUserId(userId);
    }

    @Override
    public void insertUserPassword(UserPasswordDo userPasswordDo) {
        if(StringUtils.isEmpty(userPasswordDo.getEncrptPassword())
                ||userPasswordDo.getUserId() == null){
            throw ExceptionFactory.bizException(BizCommonError.PARAMETER_VALIDATION_ERROR.getErrCode(),
                    BizCommonError.PARAMETER_VALIDATION_ERROR.getErrMsg());
        }
        userPasswordDoMapper.insertSelective(userPasswordDo);
    }
}
